<!-- HTML header for doxygen 1.8.3.1-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.4"/>
<title>CUB: cub::BlockReduce&lt; T, BLOCK_THREADS, ALGORITHM &gt; Class Template Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-38890655-1']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">CUB
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.4 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Groups</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="namespacecub.html">cub</a></li><li class="navelem"><a class="el" href="classcub_1_1_block_reduce.html">BlockReduce</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#nested-classes">Classes</a> &#124;
<a href="classcub_1_1_block_reduce-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">cub::BlockReduce&lt; T, BLOCK_THREADS, ALGORITHM &gt; Class Template Reference<div class="ingroups"><a class="el" href="group___block_module.html">Block-wide</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">Detailed description</h2>
<div class="textblock"><h3>template&lt;
    typename T, 
    int BLOCK_THREADS, 
    BlockReduceAlgorithm ALGORITHM = BLOCK_REDUCE_RAKING&gt;<br/>
class cub::BlockReduce&lt; T, BLOCK_THREADS, ALGORITHM &gt;</h3>

<p>The <a class="el" href="classcub_1_1_block_reduce.html" title="The BlockReduce class provides collective methods for computing a parallel reduction of items partiti...">BlockReduce</a> class provides <a href="index.html#sec0"><em>collective</em></a> methods for computing a parallel reduction of items partitioned across a CUDA thread block. </p>
<div class="image">
<img src="reduce_logo.png" alt="reduce_logo.png"/>
<div class="caption">
.</div></div>
 <dl class="section user"><dt>Overview</dt><dd>A <a href="http://en.wikipedia.org/wiki/Reduce_(higher-order_function)"><em>reduction</em></a> (or <em>fold</em>) uses a binary combining operator to compute a single aggregate from a list of input elements.</dd></dl>
<dl class="section user"><dt></dt><dd>Optionally, <a class="el" href="classcub_1_1_block_reduce.html" title="The BlockReduce class provides collective methods for computing a parallel reduction of items partiti...">BlockReduce</a> can be specialized by algorithm to accommodate different latency/throughput workload profiles:<ol type="1">
<li><b><a class="el" href="namespacecub.html#add0251c713859b8974806079e498d10aab32651e17a8a42207e74b7ed8d1aa4d2">cub::BLOCK_REDUCE_RAKING</a></b>. An efficient "raking" reduction algorithm. <a class="el" href="namespacecub.html#add0251c713859b8974806079e498d10a">More...</a></li>
<li><b><a class="el" href="namespacecub.html#add0251c713859b8974806079e498d10aa993903176f938273fa1ff5d4daa808e5">cub::BLOCK_REDUCE_WARP_REDUCTIONS</a></b>. A quick "tiled warp-reductions" reduction algorithm. <a class="el" href="namespacecub.html#add0251c713859b8974806079e498d10a">More...</a></li>
</ol>
</dd></dl>
<dl class="tparams"><dt>Template Parameters</dt><dd>
  <table class="tparams">
    <tr><td class="paramname">T</td><td>Data type being reduced </td></tr>
    <tr><td class="paramname">BLOCK_THREADS</td><td>The thread block size in threads </td></tr>
    <tr><td class="paramname">ALGORITHM</td><td><b>[optional]</b> <a class="el" href="namespacecub.html#add0251c713859b8974806079e498d10a">cub::BlockReduceAlgorithm</a> enumerator specifying the underlying algorithm to use (default: <a class="el" href="namespacecub.html#add0251c713859b8974806079e498d10aab32651e17a8a42207e74b7ed8d1aa4d2">cub::BLOCK_REDUCE_RAKING</a>)</td></tr>
  </table>
  </dd>
</dl>
<dl class="section user"><dt>Performance Considerations</dt><dd><ul>
<li>Very efficient (only one synchronization barrier).</li>
<li>Zero bank conflicts for most types.</li>
<li>Computation is slightly more efficient (i.e., having lower instruction overhead) for:<ul>
<li>Summation (<b><em>vs.</em></b> generic reduction)</li>
<li><code>BLOCK_THREADS</code> is a multiple of the architecture's warp size</li>
<li>Every thread has a valid input (i.e., full <b><em>vs.</em></b> partial-tiles)</li>
</ul>
</li>
<li>See <a class="el" href="namespacecub.html#add0251c713859b8974806079e498d10a">cub::BlockReduceAlgorithm</a> for performance details regarding algorithmic alternatives</li>
</ul>
</dd></dl>
<dl class="section user"><dt>A Simple Example</dt><dd>Every thread in the block uses the <a class="el" href="classcub_1_1_block_reduce.html" title="The BlockReduce class provides collective methods for computing a parallel reduction of items partiti...">BlockReduce</a> class by first specializing the <a class="el" href="classcub_1_1_block_reduce.html" title="The BlockReduce class provides collective methods for computing a parallel reduction of items partiti...">BlockReduce</a> type, then instantiating an instance with parameters for communication, and finally invoking collective member functions. </dd></dl>
<dl class="section user"><dt></dt><dd>The code snippet below illustrates a sum reduction of 512 integer items that are partitioned in a <a href="index.html#sec5sec4"><em>blocked arrangement</em></a> across 128 threads where each thread owns 4 consecutive items. </dd></dl>
<dl class="section user"><dt></dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="cub_8cuh.html">cub/cub.cuh</a>&gt;</span></div>
<div class="line"></div>
<div class="line">__global__ <span class="keywordtype">void</span> ExampleKernel(...)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">// Specialize BlockReduce for 128 threads on type int</span></div>
<div class="line">    <span class="keyword">typedef</span> <a class="code" href="classcub_1_1_block_reduce.html" title="The BlockReduce class provides collective methods for computing a parallel reduction of items partiti...">cub::BlockReduce&lt;int, 128&gt;</a> <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Allocate shared memory for BlockReduce</span></div>
<div class="line">    __shared__ <span class="keyword">typename</span> BlockReduce::TempStorage temp_storage;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Obtain a segment of consecutive items that are blocked across threads</span></div>
<div class="line">    <span class="keywordtype">int</span> thread_data[4];</div>
<div class="line">    ...</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Compute the block-wide sum for thread0</span></div>
<div class="line">    <span class="keywordtype">int</span> aggregate = <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>(temp_storage).Sum(thread_data);</div>
</div><!-- fragment --> </dd></dl>

<p>Definition at line <a class="el" href="block__reduce_8cuh_source.html#l00172">172</a> of file <a class="el" href="block__reduce_8cuh_source.html">block_reduce.cuh</a>.</p>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
Classes</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="structcub_1_1_block_reduce_1_1_temp_storage.html">TempStorage</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">The operations exposed by <a class="el" href="classcub_1_1_block_reduce.html" title="The BlockReduce class provides collective methods for computing a parallel reduction of items partiti...">BlockReduce</a> require a temporary memory allocation of this nested type for thread communication. This opaque storage can be allocated directly using the <code>__shared__</code> keyword. Alternatively, it can be aliased to externally allocated memory (shared or global) or <code>union</code>'d with other storage allocation types to facilitate memory reuse.  <a href="structcub_1_1_block_reduce_1_1_temp_storage.html#details">More...</a><br/></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Methods</h2></td></tr>
<tr><td colspan="2"><div class="groupHeader">Collective constructors</div></td></tr>
<tr class="memitem:a3d1fab4feec5bcca9c058c98dcc2e169"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a3d1fab4feec5bcca9c058c98dcc2e169"></a>
__device__ __forceinline__&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169">BlockReduce</a> ()</td></tr>
<tr class="memdesc:a3d1fab4feec5bcca9c058c98dcc2e169"><td class="mdescLeft">&#160;</td><td class="mdescRight">Collective constructor for 1D thread blocks using a private static allocation of shared memory as temporary storage. Threads are identified using <code>threadIdx.x</code>. <br/></td></tr>
<tr class="separator:a3d1fab4feec5bcca9c058c98dcc2e169"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9687391e0384a76271c9b25410f5d377"><td class="memItemLeft" align="right" valign="top">__device__ __forceinline__&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcub_1_1_block_reduce.html#a9687391e0384a76271c9b25410f5d377">BlockReduce</a> (<a class="el" href="structcub_1_1_block_reduce_1_1_temp_storage.html">TempStorage</a> &amp;temp_storage)</td></tr>
<tr class="memdesc:a9687391e0384a76271c9b25410f5d377"><td class="mdescLeft">&#160;</td><td class="mdescRight">Collective constructor for 1D thread blocks using the specified memory allocation as temporary storage. Threads are identified using <code>threadIdx.x</code>.  <a href="#a9687391e0384a76271c9b25410f5d377">More...</a><br/></td></tr>
<tr class="separator:a9687391e0384a76271c9b25410f5d377"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a126757e3d17a046190ed6e4383d8f615"><td class="memItemLeft" align="right" valign="top">__device__ __forceinline__&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcub_1_1_block_reduce.html#a126757e3d17a046190ed6e4383d8f615">BlockReduce</a> (int linear_tid)</td></tr>
<tr class="memdesc:a126757e3d17a046190ed6e4383d8f615"><td class="mdescLeft">&#160;</td><td class="mdescRight">Collective constructor using a private static allocation of shared memory as temporary storage. Each thread is identified using the supplied linear thread identifier.  <a href="#a126757e3d17a046190ed6e4383d8f615">More...</a><br/></td></tr>
<tr class="separator:a126757e3d17a046190ed6e4383d8f615"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1def8cd84b121828acbdf41a307efa46"><td class="memItemLeft" align="right" valign="top">__device__ __forceinline__&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcub_1_1_block_reduce.html#a1def8cd84b121828acbdf41a307efa46">BlockReduce</a> (<a class="el" href="structcub_1_1_block_reduce_1_1_temp_storage.html">TempStorage</a> &amp;temp_storage, int linear_tid)</td></tr>
<tr class="memdesc:a1def8cd84b121828acbdf41a307efa46"><td class="mdescLeft">&#160;</td><td class="mdescRight">Collective constructor using the specified memory allocation as temporary storage. Each thread is identified using the supplied linear thread identifier.  <a href="#a1def8cd84b121828acbdf41a307efa46">More...</a><br/></td></tr>
<tr class="separator:a1def8cd84b121828acbdf41a307efa46"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr><td colspan="2"><div class="groupHeader">Generic reductions</div></td></tr>
<tr class="memitem:a77dac72eafb56f394762b8d3b937de79"><td class="memTemplParams" colspan="2">template&lt;typename ReductionOp &gt; </td></tr>
<tr class="memitem:a77dac72eafb56f394762b8d3b937de79"><td class="memTemplItemLeft" align="right" valign="top">__device__ __forceinline__ T&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classcub_1_1_block_reduce.html#a77dac72eafb56f394762b8d3b937de79">Reduce</a> (T input, ReductionOp reduction_op)</td></tr>
<tr class="memdesc:a77dac72eafb56f394762b8d3b937de79"><td class="mdescLeft">&#160;</td><td class="mdescRight">Computes a block-wide reduction for thread<sub>0</sub> using the specified binary reduction functor. Each thread contributes one input element.  <a href="#a77dac72eafb56f394762b8d3b937de79">More...</a><br/></td></tr>
<tr class="separator:a77dac72eafb56f394762b8d3b937de79"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a40ea5f85fa38ac1ac9ec98db9b085ed0"><td class="memTemplParams" colspan="2">template&lt;int ITEMS_PER_THREAD, typename ReductionOp &gt; </td></tr>
<tr class="memitem:a40ea5f85fa38ac1ac9ec98db9b085ed0"><td class="memTemplItemLeft" align="right" valign="top">__device__ __forceinline__ T&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classcub_1_1_block_reduce.html#a40ea5f85fa38ac1ac9ec98db9b085ed0">Reduce</a> (T(&amp;inputs)[ITEMS_PER_THREAD], ReductionOp reduction_op)</td></tr>
<tr class="memdesc:a40ea5f85fa38ac1ac9ec98db9b085ed0"><td class="mdescLeft">&#160;</td><td class="mdescRight">Computes a block-wide reduction for thread<sub>0</sub> using the specified binary reduction functor. Each thread contributes an array of consecutive input elements.  <a href="#a40ea5f85fa38ac1ac9ec98db9b085ed0">More...</a><br/></td></tr>
<tr class="separator:a40ea5f85fa38ac1ac9ec98db9b085ed0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0c9d086cb37f41a74d1a4c02fae741c4"><td class="memTemplParams" colspan="2">template&lt;typename ReductionOp &gt; </td></tr>
<tr class="memitem:a0c9d086cb37f41a74d1a4c02fae741c4"><td class="memTemplItemLeft" align="right" valign="top">__device__ __forceinline__ T&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classcub_1_1_block_reduce.html#a0c9d086cb37f41a74d1a4c02fae741c4">Reduce</a> (T input, ReductionOp reduction_op, int num_valid)</td></tr>
<tr class="memdesc:a0c9d086cb37f41a74d1a4c02fae741c4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Computes a block-wide reduction for thread<sub>0</sub> using the specified binary reduction functor. The first <code>num_valid</code> threads each contribute one input element.  <a href="#a0c9d086cb37f41a74d1a4c02fae741c4">More...</a><br/></td></tr>
<tr class="separator:a0c9d086cb37f41a74d1a4c02fae741c4"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr><td colspan="2"><div class="groupHeader">Summation reductions</div></td></tr>
<tr class="memitem:a7565f00c47dc7dfb286668bea15dad05"><td class="memItemLeft" align="right" valign="top">__device__ __forceinline__ T&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcub_1_1_block_reduce.html#a7565f00c47dc7dfb286668bea15dad05">Sum</a> (T input)</td></tr>
<tr class="memdesc:a7565f00c47dc7dfb286668bea15dad05"><td class="mdescLeft">&#160;</td><td class="mdescRight">Computes a block-wide reduction for thread<sub>0</sub> using addition (+) as the reduction operator. Each thread contributes one input element.  <a href="#a7565f00c47dc7dfb286668bea15dad05">More...</a><br/></td></tr>
<tr class="separator:a7565f00c47dc7dfb286668bea15dad05"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2611610d09bb8daca91e414a77c1e937"><td class="memTemplParams" colspan="2">template&lt;int ITEMS_PER_THREAD&gt; </td></tr>
<tr class="memitem:a2611610d09bb8daca91e414a77c1e937"><td class="memTemplItemLeft" align="right" valign="top">__device__ __forceinline__ T&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classcub_1_1_block_reduce.html#a2611610d09bb8daca91e414a77c1e937">Sum</a> (T(&amp;inputs)[ITEMS_PER_THREAD])</td></tr>
<tr class="memdesc:a2611610d09bb8daca91e414a77c1e937"><td class="mdescLeft">&#160;</td><td class="mdescRight">Computes a block-wide reduction for thread<sub>0</sub> using addition (+) as the reduction operator. Each thread contributes an array of consecutive input elements.  <a href="#a2611610d09bb8daca91e414a77c1e937">More...</a><br/></td></tr>
<tr class="separator:a2611610d09bb8daca91e414a77c1e937"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa52adf836e96dee812f456283cac13f7"><td class="memItemLeft" align="right" valign="top">__device__ __forceinline__ T&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classcub_1_1_block_reduce.html#aa52adf836e96dee812f456283cac13f7">Sum</a> (T input, int num_valid)</td></tr>
<tr class="memdesc:aa52adf836e96dee812f456283cac13f7"><td class="mdescLeft">&#160;</td><td class="mdescRight">Computes a block-wide reduction for thread<sub>0</sub> using addition (+) as the reduction operator. The first <code>num_valid</code> threads each contribute one input element.  <a href="#aa52adf836e96dee812f456283cac13f7">More...</a><br/></td></tr>
<tr class="separator:aa52adf836e96dee812f456283cac13f7"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="a9687391e0384a76271c9b25410f5d377"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T , int BLOCK_THREADS, BlockReduceAlgorithm ALGORITHM = BLOCK_REDUCE_RAKING&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">__device__ __forceinline__ <a class="el" href="classcub_1_1_block_reduce.html">cub::BlockReduce</a>&lt; T, BLOCK_THREADS, ALGORITHM &gt;::<a class="el" href="classcub_1_1_block_reduce.html">BlockReduce</a> </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structcub_1_1_block_reduce_1_1_temp_storage.html">TempStorage</a> &amp;&#160;</td>
          <td class="paramname"><em>temp_storage</em>)</td><td></td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Collective constructor for 1D thread blocks using the specified memory allocation as temporary storage. Threads are identified using <code>threadIdx.x</code>. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">temp_storage</td><td>Reference to memory allocation having layout type <a class="el" href="structcub_1_1_block_reduce_1_1_temp_storage.html" title="The operations exposed by BlockReduce require a temporary memory allocation of this nested type for t...">TempStorage</a> </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="block__reduce_8cuh_source.html#l00236">236</a> of file <a class="el" href="block__reduce_8cuh_source.html">block_reduce.cuh</a>.</p>

</div>
</div>
<a class="anchor" id="a126757e3d17a046190ed6e4383d8f615"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T , int BLOCK_THREADS, BlockReduceAlgorithm ALGORITHM = BLOCK_REDUCE_RAKING&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">__device__ __forceinline__ <a class="el" href="classcub_1_1_block_reduce.html">cub::BlockReduce</a>&lt; T, BLOCK_THREADS, ALGORITHM &gt;::<a class="el" href="classcub_1_1_block_reduce.html">BlockReduce</a> </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>linear_tid</em>)</td><td></td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Collective constructor using a private static allocation of shared memory as temporary storage. Each thread is identified using the supplied linear thread identifier. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">linear_tid</td><td>A suitable 1D thread-identifier for the calling thread (e.g., <code>(threadIdx.y * blockDim.x) + linear_tid</code> for 2D thread blocks) </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="block__reduce_8cuh_source.html#l00247">247</a> of file <a class="el" href="block__reduce_8cuh_source.html">block_reduce.cuh</a>.</p>

</div>
</div>
<a class="anchor" id="a1def8cd84b121828acbdf41a307efa46"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T , int BLOCK_THREADS, BlockReduceAlgorithm ALGORITHM = BLOCK_REDUCE_RAKING&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">__device__ __forceinline__ <a class="el" href="classcub_1_1_block_reduce.html">cub::BlockReduce</a>&lt; T, BLOCK_THREADS, ALGORITHM &gt;::<a class="el" href="classcub_1_1_block_reduce.html">BlockReduce</a> </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structcub_1_1_block_reduce_1_1_temp_storage.html">TempStorage</a> &amp;&#160;</td>
          <td class="paramname"><em>temp_storage</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>linear_tid</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Collective constructor using the specified memory allocation as temporary storage. Each thread is identified using the supplied linear thread identifier. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">temp_storage</td><td>Reference to memory allocation having layout type <a class="el" href="structcub_1_1_block_reduce_1_1_temp_storage.html" title="The operations exposed by BlockReduce require a temporary memory allocation of this nested type for t...">TempStorage</a> </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">linear_tid</td><td><b>[optional]</b> A suitable 1D thread-identifier for the calling thread (e.g., <code>(threadIdx.y * blockDim.x) + linear_tid</code> for 2D thread blocks) </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="block__reduce_8cuh_source.html#l00258">258</a> of file <a class="el" href="block__reduce_8cuh_source.html">block_reduce.cuh</a>.</p>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="a77dac72eafb56f394762b8d3b937de79"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T , int BLOCK_THREADS, BlockReduceAlgorithm ALGORITHM = BLOCK_REDUCE_RAKING&gt; </div>
<div class="memtemplate">
template&lt;typename ReductionOp &gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">__device__ __forceinline__ T <a class="el" href="classcub_1_1_block_reduce.html">cub::BlockReduce</a>&lt; T, BLOCK_THREADS, ALGORITHM &gt;::Reduce </td>
          <td>(</td>
          <td class="paramtype">T&#160;</td>
          <td class="paramname"><em>input</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">ReductionOp&#160;</td>
          <td class="paramname"><em>reduction_op</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Computes a block-wide reduction for thread<sub>0</sub> using the specified binary reduction functor. Each thread contributes one input element. </p>
<p>The return value is undefined in threads other than thread<sub>0</sub>.</p>
<p>Supports non-commutative reduction operators.</p>
<p>A subsequent <code>__syncthreads()</code> threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., <code>temp_storage</code>) is to be reused or repurposed.</p>
<p>The code snippet below illustrates a max reduction of 128 integer items that are partitioned across 128 threads. </p>
<dl class="section user"><dt></dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="cub_8cuh.html">cub/cub.cuh</a>&gt;</span></div>
<div class="line"></div>
<div class="line">__global__ <span class="keywordtype">void</span> ExampleKernel(...)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">// Specialize BlockReduce for 128 threads on type int</span></div>
<div class="line">    <span class="keyword">typedef</span> <a class="code" href="classcub_1_1_block_reduce.html" title="The BlockReduce class provides collective methods for computing a parallel reduction of items partiti...">cub::BlockReduce&lt;int, 128&gt;</a> <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Allocate shared memory for BlockReduce</span></div>
<div class="line">    __shared__ <span class="keyword">typename</span> BlockReduce::TempStorage temp_storage;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Each thread obtains an input item</span></div>
<div class="line">    <span class="keywordtype">int</span> thread_data;</div>
<div class="line">    ...</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Compute the block-wide max for thread0</span></div>
<div class="line">    <span class="keywordtype">int</span> aggregate = <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>(temp_storage).Reduce(thread_data, <a class="code" href="structcub_1_1_max.html" title="Default max functor. ">cub::Max</a>());</div>
</div><!-- fragment --></dd></dl>
<dl class="tparams"><dt>Template Parameters</dt><dd>
  <table class="tparams">
    <tr><td class="paramname">ReductionOp</td><td><b>[inferred]</b> Binary reduction operator type having member <code>T operator()(const T &amp;a, const T &amp;b)</code> </td></tr>
  </table>
  </dd>
</dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">input</td><td>Calling thread's input </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">reduction_op</td><td>Binary reduction operator </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="block__reduce_8cuh_source.html#l00310">310</a> of file <a class="el" href="block__reduce_8cuh_source.html">block_reduce.cuh</a>.</p>

</div>
</div>
<a class="anchor" id="a40ea5f85fa38ac1ac9ec98db9b085ed0"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T , int BLOCK_THREADS, BlockReduceAlgorithm ALGORITHM = BLOCK_REDUCE_RAKING&gt; </div>
<div class="memtemplate">
template&lt;int ITEMS_PER_THREAD, typename ReductionOp &gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">__device__ __forceinline__ T <a class="el" href="classcub_1_1_block_reduce.html">cub::BlockReduce</a>&lt; T, BLOCK_THREADS, ALGORITHM &gt;::Reduce </td>
          <td>(</td>
          <td class="paramtype">T(&amp;)&#160;</td>
          <td class="paramname"><em>inputs</em>[ITEMS_PER_THREAD], </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">ReductionOp&#160;</td>
          <td class="paramname"><em>reduction_op</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Computes a block-wide reduction for thread<sub>0</sub> using the specified binary reduction functor. Each thread contributes an array of consecutive input elements. </p>
<p>The return value is undefined in threads other than thread<sub>0</sub>.</p>
<p>Supports non-commutative reduction operators.</p>
<p>Assumes a <a href="index.html#sec5sec4"><em>blocked arrangement</em></a> of elements across threads, where thread<sub><em>i</em></sub> owns the <em>i</em><sup>th</sup> segment of consecutively ranked items.</p>
<p>A subsequent <code>__syncthreads()</code> threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., <code>temp_storage</code>) is to be reused or repurposed.</p>
<p>The code snippet below illustrates a max reduction of 512 integer items that are partitioned in a <a href="index.html#sec5sec4"><em>blocked arrangement</em></a> across 128 threads where each thread owns 4 consecutive items. </p>
<dl class="section user"><dt></dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="cub_8cuh.html">cub/cub.cuh</a>&gt;</span></div>
<div class="line"></div>
<div class="line">__global__ <span class="keywordtype">void</span> ExampleKernel(...)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">// Specialize BlockReduce for 128 threads on type int</span></div>
<div class="line">    <span class="keyword">typedef</span> <a class="code" href="classcub_1_1_block_reduce.html" title="The BlockReduce class provides collective methods for computing a parallel reduction of items partiti...">cub::BlockReduce&lt;int, 128&gt;</a> <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Allocate shared memory for BlockReduce</span></div>
<div class="line">    __shared__ <span class="keyword">typename</span> BlockReduce::TempStorage temp_storage;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Obtain a segment of consecutive items that are blocked across threads</span></div>
<div class="line">    <span class="keywordtype">int</span> thread_data[4];</div>
<div class="line">    ...</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Compute the block-wide max for thread0</span></div>
<div class="line">    <span class="keywordtype">int</span> aggregate = <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>(temp_storage).Reduce(thread_data, <a class="code" href="structcub_1_1_max.html" title="Default max functor. ">cub::Max</a>());</div>
</div><!-- fragment --></dd></dl>
<dl class="tparams"><dt>Template Parameters</dt><dd>
  <table class="tparams">
    <tr><td class="paramname">ITEMS_PER_THREAD</td><td><b>[inferred]</b> The number of consecutive items partitioned onto each thread. </td></tr>
    <tr><td class="paramname">ReductionOp</td><td><b>[inferred]</b> Binary reduction operator type having member <code>T operator()(const T &amp;a, const T &amp;b)</code> </td></tr>
  </table>
  </dd>
</dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">inputs</td><td>Calling thread's input segment </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">reduction_op</td><td>Binary reduction operator </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="block__reduce_8cuh_source.html#l00359">359</a> of file <a class="el" href="block__reduce_8cuh_source.html">block_reduce.cuh</a>.</p>

</div>
</div>
<a class="anchor" id="a0c9d086cb37f41a74d1a4c02fae741c4"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T , int BLOCK_THREADS, BlockReduceAlgorithm ALGORITHM = BLOCK_REDUCE_RAKING&gt; </div>
<div class="memtemplate">
template&lt;typename ReductionOp &gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">__device__ __forceinline__ T <a class="el" href="classcub_1_1_block_reduce.html">cub::BlockReduce</a>&lt; T, BLOCK_THREADS, ALGORITHM &gt;::Reduce </td>
          <td>(</td>
          <td class="paramtype">T&#160;</td>
          <td class="paramname"><em>input</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">ReductionOp&#160;</td>
          <td class="paramname"><em>reduction_op</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>num_valid</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Computes a block-wide reduction for thread<sub>0</sub> using the specified binary reduction functor. The first <code>num_valid</code> threads each contribute one input element. </p>
<p>The return value is undefined in threads other than thread<sub>0</sub>.</p>
<p>Supports non-commutative reduction operators.</p>
<p>Assumes a <a href="index.html#sec5sec4"><em>blocked arrangement</em></a> of elements across threads, where thread<sub><em>i</em></sub> owns the <em>i</em><sup>th</sup> segment of consecutively ranked items.</p>
<p>A subsequent <code>__syncthreads()</code> threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., <code>temp_storage</code>) is to be reused or repurposed.</p>
<p>The code snippet below illustrates a max reduction of a partially-full tile of integer items that are partitioned across 128 threads. </p>
<dl class="section user"><dt></dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="cub_8cuh.html">cub/cub.cuh</a>&gt;</span></div>
<div class="line"></div>
<div class="line">__global__ <span class="keywordtype">void</span> ExampleKernel(<span class="keywordtype">int</span> num_valid, ...)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">// Specialize BlockReduce for 128 threads on type int</span></div>
<div class="line">    <span class="keyword">typedef</span> <a class="code" href="classcub_1_1_block_reduce.html" title="The BlockReduce class provides collective methods for computing a parallel reduction of items partiti...">cub::BlockReduce&lt;int, 128&gt;</a> <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Allocate shared memory for BlockReduce</span></div>
<div class="line">    __shared__ <span class="keyword">typename</span> BlockReduce::TempStorage temp_storage;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Each thread obtains an input item</span></div>
<div class="line">    <span class="keywordtype">int</span> thread_data;</div>
<div class="line">    <span class="keywordflow">if</span> (threadIdx.x &lt; num_valid) thread_data = ...</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Compute the block-wide max for thread0</span></div>
<div class="line">    <span class="keywordtype">int</span> aggregate = <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>(temp_storage).Reduce(thread_data, <a class="code" href="structcub_1_1_max.html" title="Default max functor. ">cub::Max</a>(), num_valid);</div>
</div><!-- fragment --></dd></dl>
<dl class="tparams"><dt>Template Parameters</dt><dd>
  <table class="tparams">
    <tr><td class="paramname">ReductionOp</td><td><b>[inferred]</b> Binary reduction operator type having member <code>T operator()(const T &amp;a, const T &amp;b)</code> </td></tr>
  </table>
  </dd>
</dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">input</td><td>Calling thread's input </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">reduction_op</td><td>Binary reduction operator </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">num_valid</td><td>Number of threads containing valid elements (may be less than BLOCK_THREADS) </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="block__reduce_8cuh_source.html#l00406">406</a> of file <a class="el" href="block__reduce_8cuh_source.html">block_reduce.cuh</a>.</p>

</div>
</div>
<a class="anchor" id="a7565f00c47dc7dfb286668bea15dad05"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T , int BLOCK_THREADS, BlockReduceAlgorithm ALGORITHM = BLOCK_REDUCE_RAKING&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">__device__ __forceinline__ T <a class="el" href="classcub_1_1_block_reduce.html">cub::BlockReduce</a>&lt; T, BLOCK_THREADS, ALGORITHM &gt;::<a class="el" href="structcub_1_1_sum.html">Sum</a> </td>
          <td>(</td>
          <td class="paramtype">T&#160;</td>
          <td class="paramname"><em>input</em>)</td><td></td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Computes a block-wide reduction for thread<sub>0</sub> using addition (+) as the reduction operator. Each thread contributes one input element. </p>
<p>The return value is undefined in threads other than thread<sub>0</sub>.</p>
<p>A subsequent <code>__syncthreads()</code> threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., <code>temp_storage</code>) is to be reused or repurposed.</p>
<p>The code snippet below illustrates a sum reduction of 128 integer items that are partitioned across 128 threads. </p>
<dl class="section user"><dt></dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="cub_8cuh.html">cub/cub.cuh</a>&gt;</span></div>
<div class="line"></div>
<div class="line">__global__ <span class="keywordtype">void</span> ExampleKernel(...)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">// Specialize BlockReduce for 128 threads on type int</span></div>
<div class="line">    <span class="keyword">typedef</span> <a class="code" href="classcub_1_1_block_reduce.html" title="The BlockReduce class provides collective methods for computing a parallel reduction of items partiti...">cub::BlockReduce&lt;int, 128&gt;</a> <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Allocate shared memory for BlockReduce</span></div>
<div class="line">    __shared__ <span class="keyword">typename</span> BlockReduce::TempStorage temp_storage;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Each thread obtains an input item</span></div>
<div class="line">    <span class="keywordtype">int</span> thread_data;</div>
<div class="line">    ...</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Compute the block-wide sum for thread0</span></div>
<div class="line">    <span class="keywordtype">int</span> aggregate = <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>(temp_storage).Sum(thread_data);</div>
</div><!-- fragment --> </dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">input</td><td>Calling thread's input </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="block__reduce_8cuh_source.html#l00461">461</a> of file <a class="el" href="block__reduce_8cuh_source.html">block_reduce.cuh</a>.</p>

</div>
</div>
<a class="anchor" id="a2611610d09bb8daca91e414a77c1e937"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T , int BLOCK_THREADS, BlockReduceAlgorithm ALGORITHM = BLOCK_REDUCE_RAKING&gt; </div>
<div class="memtemplate">
template&lt;int ITEMS_PER_THREAD&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">__device__ __forceinline__ T <a class="el" href="classcub_1_1_block_reduce.html">cub::BlockReduce</a>&lt; T, BLOCK_THREADS, ALGORITHM &gt;::<a class="el" href="structcub_1_1_sum.html">Sum</a> </td>
          <td>(</td>
          <td class="paramtype">T(&amp;)&#160;</td>
          <td class="paramname"><em>inputs</em>[ITEMS_PER_THREAD])</td><td></td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Computes a block-wide reduction for thread<sub>0</sub> using addition (+) as the reduction operator. Each thread contributes an array of consecutive input elements. </p>
<p>The return value is undefined in threads other than thread<sub>0</sub>.</p>
<p>A subsequent <code>__syncthreads()</code> threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., <code>temp_storage</code>) is to be reused or repurposed.</p>
<p>The code snippet below illustrates a sum reduction of 512 integer items that are partitioned in a <a href="index.html#sec5sec4"><em>blocked arrangement</em></a> across 128 threads where each thread owns 4 consecutive items. </p>
<dl class="section user"><dt></dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="cub_8cuh.html">cub/cub.cuh</a>&gt;</span></div>
<div class="line"></div>
<div class="line">__global__ <span class="keywordtype">void</span> ExampleKernel(...)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">// Specialize BlockReduce for 128 threads on type int</span></div>
<div class="line">    <span class="keyword">typedef</span> <a class="code" href="classcub_1_1_block_reduce.html" title="The BlockReduce class provides collective methods for computing a parallel reduction of items partiti...">cub::BlockReduce&lt;int, 128&gt;</a> <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Allocate shared memory for BlockReduce</span></div>
<div class="line">    __shared__ <span class="keyword">typename</span> BlockReduce::TempStorage temp_storage;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Obtain a segment of consecutive items that are blocked across threads</span></div>
<div class="line">    <span class="keywordtype">int</span> thread_data[4];</div>
<div class="line">    ...</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Compute the block-wide sum for thread0</span></div>
<div class="line">    <span class="keywordtype">int</span> aggregate = <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>(temp_storage).Sum(thread_data);</div>
</div><!-- fragment --></dd></dl>
<dl class="tparams"><dt>Template Parameters</dt><dd>
  <table class="tparams">
    <tr><td class="paramname">ITEMS_PER_THREAD</td><td><b>[inferred]</b> The number of consecutive items partitioned onto each thread. </td></tr>
  </table>
  </dd>
</dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">inputs</td><td>Calling thread's input segment </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="block__reduce_8cuh_source.html#l00501">501</a> of file <a class="el" href="block__reduce_8cuh_source.html">block_reduce.cuh</a>.</p>

</div>
</div>
<a class="anchor" id="aa52adf836e96dee812f456283cac13f7"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T , int BLOCK_THREADS, BlockReduceAlgorithm ALGORITHM = BLOCK_REDUCE_RAKING&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">__device__ __forceinline__ T <a class="el" href="classcub_1_1_block_reduce.html">cub::BlockReduce</a>&lt; T, BLOCK_THREADS, ALGORITHM &gt;::<a class="el" href="structcub_1_1_sum.html">Sum</a> </td>
          <td>(</td>
          <td class="paramtype">T&#160;</td>
          <td class="paramname"><em>input</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>num_valid</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Computes a block-wide reduction for thread<sub>0</sub> using addition (+) as the reduction operator. The first <code>num_valid</code> threads each contribute one input element. </p>
<p>The return value is undefined in threads other than thread<sub>0</sub>.</p>
<p>A subsequent <code>__syncthreads()</code> threadblock barrier should be invoked after calling this method if the collective's temporary storage (e.g., <code>temp_storage</code>) is to be reused or repurposed.</p>
<p>The code snippet below illustrates a sum reduction of a partially-full tile of integer items that are partitioned across 128 threads. </p>
<dl class="section user"><dt></dt><dd><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="cub_8cuh.html">cub/cub.cuh</a>&gt;</span></div>
<div class="line"></div>
<div class="line">__global__ <span class="keywordtype">void</span> ExampleKernel(<span class="keywordtype">int</span> num_valid, ...)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">// Specialize BlockReduce for 128 threads on type int</span></div>
<div class="line">    <span class="keyword">typedef</span> <a class="code" href="classcub_1_1_block_reduce.html" title="The BlockReduce class provides collective methods for computing a parallel reduction of items partiti...">cub::BlockReduce&lt;int, 128&gt;</a> <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Allocate shared memory for BlockReduce</span></div>
<div class="line">    __shared__ <span class="keyword">typename</span> BlockReduce::TempStorage temp_storage;</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Each thread obtains an input item (up to num_items)</span></div>
<div class="line">    <span class="keywordtype">int</span> thread_data;</div>
<div class="line">    <span class="keywordflow">if</span> (threadIdx.x &lt; num_valid)</div>
<div class="line">        thread_data = ...</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Compute the block-wide sum for thread0</span></div>
<div class="line">    <span class="keywordtype">int</span> aggregate = <a class="code" href="classcub_1_1_block_reduce.html#a3d1fab4feec5bcca9c058c98dcc2e169" title="Collective constructor for 1D thread blocks using a private static allocation of shared memory as tem...">BlockReduce</a>(temp_storage).Sum(thread_data, num_valid);</div>
</div><!-- fragment --> </dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">input</td><td>Calling thread's input </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">num_valid</td><td>Number of threads containing valid elements (may be less than BLOCK_THREADS) </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="block__reduce_8cuh_source.html#l00542">542</a> of file <a class="el" href="block__reduce_8cuh_source.html">block_reduce.cuh</a>.</p>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="block__reduce_8cuh_source.html">block_reduce.cuh</a></li>
</ul>
</div><!-- contents -->
<!-- HTML footer for doxygen 1.8.3.1-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Aug 23 2013 17:31:11 for CUB by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.4
<br>
&copy; 2013 NVIDIA Corporation
</small></address>
</body>
</html>
